CREATE TABLE [dbo].[tb_EstadosDeReestructura]
(
[idEstadoReestructura] [int] NOT NULL IDENTITY(1, 1),
[Descripcion] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL
) ON [PRIMARY]
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE TRIGGER [dbo].[updatetb_EstadosDeReestructura] ON [dbo].[tb_EstadosDeReestructura]
 FOR UPDATE AS 
 IF (update(idEstadoReestructura)) begin 
	 SELECT * FROM inserted 
	 IF @@ROWCOUNT = 1 begin 
		 UPDATE tb_Reestructuras
		 SET Estado = (SELECT idEstadoReestructura FROM inserted)
		 WHERE tb_Reestructuras.Estado = (SELECT idEstadoReestructura FROM deleted)
		 UPDATE tb_AperturasDeReestructura
		 SET Estado = (SELECT idEstadoReestructura FROM inserted)
		 WHERE tb_AperturasDeReestructura.Estado = (SELECT idEstadoReestructura FROM deleted)
		 UPDATE tb_TransferenciasDeReestructura
		 SET Estado = (SELECT idEstadoReestructura FROM inserted)
		 WHERE tb_TransferenciasDeReestructura.Estado = (SELECT idEstadoReestructura FROM deleted)
		 UPDATE tb_CierresDeReestructura
		 SET Estado = (SELECT idEstadoReestructura FROM inserted)
		 WHERE tb_CierresDeReestructura.Estado = (SELECT idEstadoReestructura FROM deleted)
		 UPDATE tb_BajasDeTransferencia
		 SET Estado = (SELECT idEstadoReestructura FROM inserted)
		 WHERE tb_BajasDeTransferencia.Estado = (SELECT idEstadoReestructura FROM deleted)
		 UPDATE tb_AltasTransferencia
		 SET Estado = (SELECT idEstadoReestructura FROM inserted)
		 WHERE tb_AltasTransferencia.Estado = (SELECT idEstadoReestructura FROM deleted)
	end  ELSE begin 
		 ROLLBACK TRANSACTION 
 end 
 end
GO
ALTER TABLE [dbo].[tb_EstadosDeReestructura] ADD CONSTRAINT [PK_tb_EstadosDeReestructura] PRIMARY KEY NONCLUSTERED  ([idEstadoReestructura]) ON [PRIMARY]
GO
